﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace WorldMapNew
{
    /// <summary>
    /// 地图数据结构
    /// </summary>
    public class WorldMapData : ScriptableObject
    {
        public int mapWidth;                                        //地图宽，单位为米
        public int mapHeight;                                       //地图高，单位为米
        public List<MapLayerRunDta> mapLayerRunDtas;                //层级缩放策略数据 -存储当前地图使用到的层级 和 该层级对应的<lod，粒度>
        public List<MapLODData> mapLODDatas;                        //LOD数据 （！！！最重要的数据！！！）
        public List<int> mapChunckResIds;                           //沙盘地图块资源id集合 -用于初始化加载

        public List<MapChunckDeleateData> mapChunckDeleateDatas;    //沙盘地图删除数据      -用于6车道删除的装饰物 显示判断
        public List<int> mapChunckDeleatePoints;                    //沙盘地图删除出生点    -用于6车道删除的出生点 迁城模式下显示判断

        public List<int> mapAllianceDeleatePoints;                  //沙盘地图删除街区点数据 主要是奇观和关卡 -用于联盟间建筑连线

        public List<OverSeaShapeInfo> mapOverSeaShapeInfos;
        public WorldMapData()
        {
            mapLODDatas = new List<MapLODData>();
            mapLayerRunDtas = new List<MapLayerRunDta>();
            mapChunckResIds = new List<int>();
            mapChunckDeleateDatas = new List<MapChunckDeleateData>();
        }

        public void InitData(WorldMapData data)
        {
            mapWidth = data.mapWidth;
            mapHeight = data.mapHeight;
            mapLayerRunDtas = data.mapLayerRunDtas;
            mapLODDatas = data.mapLODDatas;
            mapChunckResIds = data.mapChunckResIds;
            mapChunckDeleateDatas = data.mapChunckDeleateDatas;
            mapChunckDeleatePoints = data.mapChunckDeleatePoints;
            mapAllianceDeleatePoints = data.mapAllianceDeleatePoints;
            mapOverSeaShapeInfos = data.mapOverSeaShapeInfos;
        }

        /// <summary>
        /// 添加地图的Lod数据
        /// </summary>
        /// <param name="layer"></param>
        public void AddLODData(MapLODData lodData)
        {
            mapLODDatas.Add(lodData);
        }

        /// <summary>
        /// 添加地图块id
        /// </summary>
        /// <param name="lodData"></param>
        public void AddMapChunckResId(int chunckResId)
        {
            mapChunckResIds.Add(chunckResId);
        }

        public void AddDeleateAllinacePointIdx(int idx)
        {
            if (mapAllianceDeleatePoints == null) mapAllianceDeleatePoints = new List<int>();
            mapAllianceDeleatePoints.Add(idx);
        }
    }

    public enum ResourceLoadLevel { 
        E_Load_ByLoading = 0, // loading时加载 地表
        E_Load_ByUsing = 1, // 按需加载
    }

    /// <summary>
    /// 序列化的资源数据
    /// </summary>
    [Serializable]
    public class ResourceData
    {
        public int resID;
        public string resPath;
        public int poolNum;
        public int loadLevel;

        public ResourceData(int resID, string resPath,int poolNum = 100, ResourceLoadLevel loadLevel = ResourceLoadLevel.E_Load_ByUsing)
        {
            this.resID = resID;
            this.resPath = resPath;
            this.poolNum = poolNum;
            this.loadLevel = (int)loadLevel;
        }
    }
}